package com.atguigu.spzx.manner.controller;

import com.atguigu.spzx.manner.service.CategoryService;
import com.atguigu.spzx.model.entity.Category;
import com.atguigu.spzx.model.myemun.ResultCodeEnum;
import com.atguigu.spzx.model.vo.common.Result;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Locale;

@RestController
@RequestMapping(value="/admin/product/category")
@CrossOrigin(allowCredentials = "true", originPatterns = "*", allowedHeaders = "*")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @GetMapping(value="/findByParentId/{parentId}")
    public Result<List<Category>> findByParentId(@PathVariable Long parentId){
        List<Category> list = categoryService.findByParentId(parentId);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    //导出功能
    @GetMapping("/exportData")
    public void exportData(HttpServletResponse response){
        categoryService.exportData(response);
    }
    @PostMapping("/importData")
    public Result importData(MultipartFile file){
        categoryService.importData(file);
        return Result.build( ResultCodeEnum.SUCCESS);
    }

}
